<?php
namespace app\index\controller;

use app\common\model\Banner;
use app\common\model\Theme;
use app\common\model\ThemeBook;

class Index extends Base{

    public function index(){

        //获取banner
        $banner = new Banner();
        $bannerList = $banner->where(['status'=>1])->order('sort desc')->limit(3)->select();

        //获取热门小说
        $theme = new Theme();
        $themeList = $theme->where(['status'=>1])->select();
        $themebook = new ThemeBook();
        foreach ($themeList as $key=>$theme){
            $themeList[$key]['list'] = $themebook
                ->alias('t')
                ->field('b.*,a.author_name')
                ->join('books b','t.book_id = b.book_id','inner')
                ->join('author a','a.author_id = b.author_id','inner')
                ->where(['t.status'=>1,'b.status'=>1])
                ->order('t.value desc')
                ->select();
        }

        $this->assign('bannerList',$bannerList);
        $this->assign('themeList',$themeList);
        return view();
    }
}
